package rs.mbs2.epics.server.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@SuppressWarnings("serial")
@Entity
@Table(name="profile_image")
@NamedQueries({
	@NamedQuery(name = "findByPath", query = "SELECT pi FROM ProfileImage pi WHERE pi.location LIKE :location"),
	@NamedQuery(name = "findByUserId", query = "SELECT pi FROM ProfileImage pi WHERE pi.user.id LIKE :user_id")
})
public class ProfileImage implements Serializable {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "profile_image_id", unique = true, nullable = false)
	private Integer id;
	
	@Column(name = "profile_image_location", unique = false, nullable = false)
	private String  location;
	
	@Column(name = "thumbnail_image_location", unique = false, nullable = false)
	private String  thumbnailLocation;
	
	@Column(name = "profile_image_width", unique = false, nullable = false)
	private Integer width;
	
	@Column(name = "profile_image_height", unique = false, nullable = false)
	private Integer height;
	
	@Column(name = "profile_image_size", unique = false, nullable = false)
	private Long    size;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "profile_image_upload_date", unique = false, nullable = false)
	private Date    uploadDate;
	
	@OneToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "user_id", referencedColumnName = "user_id", nullable = false)
	private User    user;
	
	
	public ProfileImage() {
		
	}

	public ProfileImage(String location, String thumbnailLocation, Integer width, Integer height,
			Long size, Date uploadDate, User user) {
		
		super();
		this.location = location;
		this.thumbnailLocation = thumbnailLocation;
		this.width = width;
		this.height = height;
		this.size = size;
		this.uploadDate = uploadDate;
		this.user = user;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public Integer getWidth() {
		return width;
	}

	public void setWidth(Integer width) {
		this.width = width;
	}

	public Integer getHeight() {
		return height;
	}

	public void setHeight(Integer height) {
		this.height = height;
	}

	public Long getSize() {
		return size;
	}

	public void setSize(Long size) {
		this.size = size;
	}

	public Date getUploadDate() {
		return uploadDate;
	}

	public void setUploadDate(Date uploadDate) {
		this.uploadDate = uploadDate;
	}

	public String getThumbnailLocation() {
		return thumbnailLocation;
	}

	public void setThumbnailLocation(String thumbnailLocation) {
		this.thumbnailLocation = thumbnailLocation;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((user == null) ? 0 : user.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ProfileImage other = (ProfileImage) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (user == null) {
			if (other.user != null)
				return false;
		} else if (!user.equals(other.user))
			return false;
		return true;
	}
	
}
